import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Hoods from '../views/Goods.vue'
import Mine from '../views/Mine.vue'
import Other from '../components/Other.vue'
import Main from '../components/Main.vue'
import Detail from '../views/Detail.vue'
Vue.use(VueRouter)

// const routes = [
//   {
//     path: '/',
//     name: 'Home',
//     component: Home
//   },
//   {
//     path: '/about',
//     name: 'About',
//     // route level code-splitting
//     // this generates a separate chunk (about.[hash].js) for this route
//     // which is lazy-loaded when the route is visited.
//     component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
//   }
// ]

// const router = new VueRouter({
//   mode: 'history',
//   base: process.env.BASE_URL,
//   routes
// })

const router = new VueRouter({
      mode:"history",
      routes: [
        {
          path: '/home',  // 导航要匹配的名字
          component : Home, // 具体要导航到哪个组件，使用的时候记得要先注册
          children: [  // 子组件，一个数组
            {
              path: 'other',
              component: Other,
            },
            {
              path: 'main',
              component: Main,
            },
           {
             path: '', 
             redirect:"main"
           }
          ]
        },
        {
          path: '/goods',
          component : Hoods
        },
        {
          path: '/mine',
          component : Mine
        },
        {
          path: '/login',
          component : () => import('../views/login.vue')
        },
        // {
        //   path: '/detail', //原生跳转可用
        //   component : Detail
        // },
        {
          path: '/detail', //命名路由
          component : Detail,
          name: 'mydetail'
        },
        // {
        //   path: '/detail/:id', //动态路由
        //   component : Detail,
        //   name: 'mydetail'
        // },
        {
          path: '*',
          redirect : '/home' // *表示所有都匹配不上的时候，重定向(匹配)哪个
        }
      ],


})

export default router
